/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.emp.solbrillante.sales.view;

import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import pe.emp.solbrillante.sale.Main;
import pe.emp.solbrillante.sales.bean.PaqueteCompra;
import pe.emp.solbrillante.sales.bean.Proveedor;

/**
 *
 * @author Ronald
 */
public class JCompra extends javax.swing.JDialog {

    
    JPedido padre;
    
    /**
     * Creates new form JCompra
     */
    public JCompra(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();    

                 //pintamos el fondo de la ventana
        ((JFondo)jventana).setImagen("fondo_subVentanal_II.jpg");        
        
                ((JFondo)jtitulo).setImagen("BarraHorizontalTitulos.png");
        ((JFondo)jfiltro).setImagen("BarraHorizontalTitulosBlanco.png");
        
         java.util.Date momentoDate = new java.util.Date();
        java.sql.Timestamp momentoTimestamp = new java.sql.Timestamp(momentoDate.getTime());
        String fecha_actual = new java.text.SimpleDateFormat("dd/MM/yyyy").format(momentoTimestamp);
        this.jTextFieldFechaActual.setText(fecha_actual);
        //pintamos el fondo de la ventana
        //((JFondo)jventana).setImagen("fondo_subVentanal_II.jpg");               
        //ArrayList<Producto> productos = Main.myService.queryAllProductos();
        ArrayList<Proveedor> proveedores = Main.myService.queryAllProveedores();       
       
         //recorremos desde 1 porque no queremos el nombre de la etiqueta
        for(int i=1; i<proveedores.size();i++ ){       
//          this.jComboBox1.addItem(proveedores.get(i).getNombre());
//          combobox de objetos :  se sobreescribe el metodo toString() en proveedores
            this.jComboBox1.addItem(proveedores.get(i));        
        }
        
    }
    
    // ayuda a traer  a la ventana padre`para usar sus metodos
    public void setPadre(JPedido padre){
        this.padre=padre;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jventana = new JFondo();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableListaPaquetesProveedorCompra = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldTotalPedido = new javax.swing.JTextField();
        jButtonGuardarCompra = new javax.swing.JButton();
        jfiltro = new JFondo();
        jLabel2 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldFechaActual = new javax.swing.JTextField();
        jtitulo = new JFondo();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Registro de Pedido a Proveedor");
        setMaximumSize(new java.awt.Dimension(850, 550));
        setMinimumSize(new java.awt.Dimension(850, 550));
        setPreferredSize(new java.awt.Dimension(850, 550));

        jventana.setMaximumSize(new java.awt.Dimension(800, 500));
        jventana.setMinimumSize(new java.awt.Dimension(800, 500));
        jventana.setPreferredSize(new java.awt.Dimension(800, 500));

        jLabel4.setText("Elija cantidades de cada paquete:");

        jTableListaPaquetesProveedorCompra.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTableListaPaquetesProveedorCompra.setPreferredSize(new java.awt.Dimension(800, 300));
        jTableListaPaquetesProveedorCompra.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jTableListaPaquetesProveedorCompraInputMethodTextChanged(evt);
            }
        });
        jTableListaPaquetesProveedorCompra.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTableListaPaquetesProveedorCompraKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTableListaPaquetesProveedorCompraKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(jTableListaPaquetesProveedorCompra);

        jLabel3.setText("Total  S/. :");

        jTextFieldTotalPedido.setText("0");

        jButtonGuardarCompra.setText("Guardar");
        jButtonGuardarCompra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarCompraActionPerformed(evt);
            }
        });

        jfiltro.setMaximumSize(new java.awt.Dimension(400, 40));
        jfiltro.setMinimumSize(new java.awt.Dimension(400, 40));
        jfiltro.setPreferredSize(new java.awt.Dimension(400, 40));

        jLabel2.setText("Proveedor :");

        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel5.setText("Hoy:");

        jTextFieldFechaActual.setText("jTextField1");

        javax.swing.GroupLayout jfiltroLayout = new javax.swing.GroupLayout(jfiltro);
        jfiltro.setLayout(jfiltroLayout);
        jfiltroLayout.setHorizontalGroup(
            jfiltroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jfiltroLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(38, 38, 38)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(46, 46, 46)
                .addComponent(jLabel5)
                .addGap(43, 43, 43)
                .addComponent(jTextFieldFechaActual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(35, Short.MAX_VALUE))
        );
        jfiltroLayout.setVerticalGroup(
            jfiltroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jfiltroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jfiltroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldFechaActual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jtitulo.setMaximumSize(new java.awt.Dimension(267, 39));
        jtitulo.setMinimumSize(new java.awt.Dimension(267, 39));
        jtitulo.setPreferredSize(new java.awt.Dimension(267, 39));

        jLabel1.setText("Registro de Pedido");

        javax.swing.GroupLayout jtituloLayout = new javax.swing.GroupLayout(jtitulo);
        jtitulo.setLayout(jtituloLayout);
        jtituloLayout.setHorizontalGroup(
            jtituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jtituloLayout.createSequentialGroup()
                .addGap(88, 88, 88)
                .addComponent(jLabel1)
                .addContainerGap(89, Short.MAX_VALUE))
        );
        jtituloLayout.setVerticalGroup(
            jtituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jtituloLayout.createSequentialGroup()
                .addContainerGap(14, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addContainerGap())
        );

        javax.swing.GroupLayout jventanaLayout = new javax.swing.GroupLayout(jventana);
        jventana.setLayout(jventanaLayout);
        jventanaLayout.setHorizontalGroup(
            jventanaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jventanaLayout.createSequentialGroup()
                .addContainerGap(542, Short.MAX_VALUE)
                .addGroup(jventanaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButtonGuardarCompra, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jventanaLayout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldTotalPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(58, 58, 58))
            .addGroup(jventanaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jfiltro, javax.swing.GroupLayout.PREFERRED_SIZE, 403, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(jventanaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
            .addGroup(jventanaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jventanaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jtitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jventanaLayout.setVerticalGroup(
            jventanaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jventanaLayout.createSequentialGroup()
                .addContainerGap(29, Short.MAX_VALUE)
                .addComponent(jtitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jfiltro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(jLabel4)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jventanaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldTotalPedido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonGuardarCompra)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jventana, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jventana, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
        
        Proveedor proveedor = (Proveedor)this.jComboBox1.getSelectedItem();
        MostarProductosDeProveedor(proveedor);
        
        
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jButtonGuardarCompraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarCompraActionPerformed
        // TODO add your handling code here:
          // TODO add your handling code here:
         Date ahora = new Date();
        SimpleDateFormat formateador = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("FECHA : " + formateador.format(ahora));
        
                    //int col = this.jTableListaPaquetesProveedor.getModel().getColumnCount();
                    int fil = this.jTableListaPaquetesProveedorCompra.getModel().getRowCount(); 
                    System.out.println("nro rows : " + fil);
                    
                   if ( this.jTextFieldTotalPedido.getText().toString().equals("0")){
                        System.out.println("SELECCIONE ALGUN PRODUCTO!");                       
                   }
                   else{
                       
                    // guardar registro del pedido:
                    //1. insertar un registro en la tabla pedido
                    System.out.println("EL TOTAL:" + Float.parseFloat(this.jTextFieldTotalPedido.getText().toString()));
                    int indice_nuevo_pedido = Main.myService.queryInsertaPedidoCompra(Float.parseFloat(this.jTextFieldTotalPedido.getText().toString()), "Pendiente" );                   
                    System.out.println("RESULTADO INSERT PEDIDO (INDICE):" + indice_nuevo_pedido);
                    
                    //2. insertar cada uno de los registros  en la tabla detalle_pedido , aquellos que no tengan subtototal 0        
                    for( int i=0; i<fil; i++)
                    {
                       int codPaquete =  Integer.parseInt( jTableListaPaquetesProveedorCompra.getModel().getValueAt(i, 0).toString() );                       
                       int cantPedida  = Integer.parseInt( jTableListaPaquetesProveedorCompra.getModel().getValueAt(i, 6).toString() );                       
                       Float subtotal  = Float.parseFloat( jTableListaPaquetesProveedorCompra.getModel().getValueAt(i, 7).toString() );//getValueAt(i, 6) modificacion!!!!!
                       
                       if (subtotal!=0.0){                           
                             System.out.println("idpedido : "+indice_nuevo_pedido+ " idpaquete : "+codPaquete+" cantped : "+cantPedida+" subtotal : "+subtotal);                             
                             int res_insert_linea_pedido = Main.myService.queryInsertaLineaDetallePedido(indice_nuevo_pedido,cantPedida,subtotal,codPaquete);
                             System.out.println("res insert linea_pedido: "+res_insert_linea_pedido);
                             System.out.println("RESULTADO INSERT LINEA PEDIDO(cod paquete):" + codPaquete);                             
                        }                    
                    System.out.println("fin recorrido");                    
               }      
       
         }   
                   padre.refreshProductTable();
                   this.dispose();
        
    }//GEN-LAST:event_jButtonGuardarCompraActionPerformed

    private void jTableListaPaquetesProveedorCompraInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jTableListaPaquetesProveedorCompraInputMethodTextChanged
        // TODO add your handling code here:
       // System.out.print("fila : " + this.jTableListaPaquetesProveedorCompra.getEditingRow()+",col : " + this.jTableListaPaquetesProveedorCompra.getEditingColumn());
    }//GEN-LAST:event_jTableListaPaquetesProveedorCompraInputMethodTextChanged

    private void jTableListaPaquetesProveedorCompraKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTableListaPaquetesProveedorCompraKeyTyped
     
    }//GEN-LAST:event_jTableListaPaquetesProveedorCompraKeyTyped

    private void jTableListaPaquetesProveedorCompraKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTableListaPaquetesProveedorCompraKeyReleased
        // TODO add your handling code here:
      //  System.out.print("fila : " + this.jTableListaPaquetesProveedorCompra.getEditingRow()+",col : " + this.jTableListaPaquetesProveedorCompra.getEditingColumn());
//        if(!Charax  cter.isDigit(e.getKeyChar()) && e.getKeyChar() !=KeyEvent.VK_BACK_SPACE)
//       System.out.println("TECLA: " + evt.getKeyChar());
//       if 
         //jTableListaPaquetesProveedorCompra.getCellEditor(WIDTH, WIDTH)
        int iRowEdit = jTableListaPaquetesProveedorCompra.getEditingRow();        
        int iColEdit = jTableListaPaquetesProveedorCompra.getEditingColumn();
        
        int colum = jTableListaPaquetesProveedorCompra.getSelectedColumn();
        int row = jTableListaPaquetesProveedorCompra.getSelectedRow();
        System.out.println("rc=" + iRowEdit +"cr=" +iColEdit + "st:"+ ",COL:" +colum+ ",ROW:" +row);
        int pedido = Integer.parseInt(jTableListaPaquetesProveedorCompra.getValueAt(row, colum).toString());
        Float precio = Float.parseFloat(jTableListaPaquetesProveedorCompra.getValueAt(row, colum-2).toString());
        Float subtotal =pedido*precio;
        jTableListaPaquetesProveedorCompra.getModel().setValueAt(subtotal, row, colum+1);
        
        this.jTextFieldTotalPedido.setText(sumaPedido().toString());
        
    }//GEN-LAST:event_jTableListaPaquetesProveedorCompraKeyReleased

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JCompra.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JCompra.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JCompra.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JCompra.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                JCompra dialog = new JCompra(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonGuardarCompra;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableListaPaquetesProveedorCompra;
    private javax.swing.JTextField jTextFieldFechaActual;
    private javax.swing.JTextField jTextFieldTotalPedido;
    private javax.swing.JPanel jfiltro;
    private javax.swing.JPanel jtitulo;
    private javax.swing.JPanel jventana;
    // End of variables declaration//GEN-END:variables

    private void MostarProductosDeProveedor(Proveedor proveedorDeproductoCompra) {
        //Declaramos las clases necesarias para la conexion     
            
            DefaultTableModel modelo;                               
            
            modelo = new DefaultTableModel(){
            boolean[] canEdit = new boolean [] { false, false,false, false, false, false , true , false};

            @Override
                         public boolean isCellEditable(int rowIndex, int columnIndex) {
                             return canEdit [columnIndex];
                         }

            };
            
            this.jTableListaPaquetesProveedorCompra.setModel(modelo); 
            
        
            
            System.out.println(proveedorDeproductoCompra.getId());   
            //ArrayList<Paquete> paquetesxproveedor = Main.myService.queryPaquetesxProveedor(proveedorDeproducto.getId());
            ArrayList<PaqueteCompra> paquetesxproveedor = Main.myService.queryPaquetesxProveedorS(proveedorDeproductoCompra.getId());
                 
    
            modelo.addColumn("Codigo");
            modelo.addColumn("Proveedor");
            modelo.addColumn("Producto");
            modelo.addColumn("Uni. Paquete");
            modelo.addColumn("Precio Paquete");
            modelo.addColumn("Stock Actual");
            
            modelo.addColumn("Cant. Pedida");
            modelo.addColumn("Subtotal");
            
            
//            this.jTableListaPaquetesProveedorCompra.getModel().addTableModelListener(new TableModelListener() {
//            @Override
//            public void tableChanged(TableModelEvent e) {
//                //JOptionPane.showMessageDialog(null, "Han cambiado los datos.");
//                int iRowEdit = jTableListaPaquetesProveedorCompra.getEditingRow();
//                int iColEdit = jTableListaPaquetesProveedorCompra.getEditingColumn();
//                System.out.println("rc=" + iRowEdit +"cr=" +iColEdit + "st:");
//                //Float subTotalRegistro = (Float) jTableListaPaquetesProveedorCompra.getValueAt(iRowEdit , 6) * (Float) jTableListaPaquetesProveedorCompra.getValueAt(iRowEdit , 4);
//                //jTableListaPaquetesProveedorCompra.getModel().setValueAt(34, 0, 7);
//                //RegCantidad(34,0,7);
//                //jTableListaPaquetesProveedorCompra.setv
//                //JOptionPane.showMessageDialog(null,"rc=" + iRowEdit +"cr=" +iColEdit);              
//                //System.out.println("rc=" + iRowEdit +"cr=" +iColEdit + "st:" + jTableListaPaquetesProveedorCompra.getValueAt(iRowEdit , 6));              
//                jTableListaPaquetesProveedorCompra.getModel().setValueAt(24 , 0,0);
//                
//                }
//
//            });
            
           System.out.println("size : " + paquetesxproveedor.size());
            for (int i = 0; i < paquetesxproveedor.size(); i++) {                           
                //Extraemos los datos del ResultSet nombre=nombre de la columna              
                Object[] fila = new Object[8];                
                
                fila[0]=paquetesxproveedor.get(i).getCodigo();
                fila[1]=paquetesxproveedor.get(i).getNom_prov();
                fila[2]=paquetesxproveedor.get(i).getNom_prd();
                fila[3]=paquetesxproveedor.get(i).getUnixpaquete();
                fila[4]=paquetesxproveedor.get(i).getPrecioxpaquete();
                fila[5]=paquetesxproveedor.get(i).getCantidad();
                fila[6]=0;
                fila[7]=0;
                
                //System.out.println(paquetesxproveedor.get(i).getId()+"..."+paquetesxproveedor.get(i).getCantidad_actual());
                modelo.addRow(fila);                  
            }                           
            //jTableListaPaquetesProveedorCompra.getModel().setValueAt(23 , 0,7);      
    }

    private Double sumaPedido() {
            Double  total_pedido;       
            total_pedido = 0.0;
            for (int i = 0; i < this.jTableListaPaquetesProveedorCompra.getRowCount(); i++) {                                           
                total_pedido = total_pedido + Float.parseFloat(jTableListaPaquetesProveedorCompra.getValueAt(i, 7).toString());              
            }   
            
            System.out.println("total:"+total_pedido);
            return total_pedido;
    }


 
}
